/**
 * 2025/01/01 - 2025/12/31
 */
package com.snail.server.database.engine.datasource.mapping;

import com.alibaba.druid.pool.DruidDataSource;
import com.snail.server.database.engine.datasource.dto.DataSourceModifyDTO;
import com.snail.server.database.engine.datasource.entity.DataSource;
import com.snail.server.database.engine.datasource.vo.DataSourceVO;
import com.snail.server.database.engine.ddl.field.enums.FieldTypeEnum;
import com.snail.starter.db.enums.EnableOrDisEnableEnum;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingConstants;

import java.util.List;

/**
 * @author zgadmin
 * @date 2025/8/28 17:51
 */
@Mapper(componentModel = MappingConstants.ComponentModel.SPRING, uses = {FieldTypeEnum.class, EnableOrDisEnableEnum.class})
public interface DataSourceMapping {

    DruidDataSource dataSource2DruidDataSource(DataSource datasource);

    @Mapping(target = "type", expression = "java(datasource.getType().getValue())")
    @Mapping(target = "status", expression = "java(datasource.getStatus().getValue())")
    @Mapping(target = "pool", expression = "java(cn.hutool.core.codec.Base64.decodeStr(datasource.getPool()))")
    DataSourceVO dataSource2DataSourceVO(DataSource datasource);

    @Mapping(target = "type", ignore = true)
    @Mapping(target = "status", ignore = true)
    @Mapping(target = "pool", ignore = true)
    DataSource dataSourceModify2DataSource(DataSourceModifyDTO dataSourceModifyDTO);

    List<DataSourceVO> batchDataSource2DataSourceVO(List<DataSource> list);

}